
<?php
if (!defined('IN_XLP')) {
    exit('Access Denied');
}
$Document = array(
    'pageid' => 'index-index', //页面标示
    'pagename' => '', //当前页面名称
    'mycss' => array('index/common','index/style'), //加载的css样式表
    'myjs' => array('global/jquery-1.9.0.min','global/layer/layer'), //加载的js脚本
    'footerjs'=>array(),
    'head'=>true//是否加载头部文件
);
include getTpl('header', 'public');
?>
<body>
<div class="home-wrap">
    <?php include getTpl('small_top' , 'public'); ?>
    <div class="home-logo">
        <img src="<?php echo IMG_PATH ?>index/logo.png"/>
    </div>
    <div class="content game_info">
        <div class="price_title">
            <h2>
                <a href="javascript:;" class="bj on" data-url="<?php echo U('index/search') ?>">游戏比价</a>
                <a href="javascript:;" class="hq" data-url="<?php echo U('index/records') ?>">历史行情</a>
            </h2>
            <div class="p_than">
                <div class="p_type">
                    <a href="javascript:;" id="gameName">游戏名称</a>
                    <a href="javascript:;" id="gameArea">游戏大区</a>
                    <a href="javascript:;" id="gameServer">游戏服务器</a>
                    <a href="javascript:;" id="gameType">物品类型</a>
                    <a href="javascript:;" id="ident">交易身份</a>
                </div>        
                <button style="cursor:pointer;" id="subBtn">立即查看</button>
            </div>
        </div>
        <div class="gameBox wr1">
            <div class="game_n active">
                <div class="g_tit">
                    <h2>
                        <span>历史选择：</span>
                        <span class="history">
                        <?php foreach ($history_games as $vo): ?>
                            <a href="javascript:;" onclick="chooseGame(this)" data-id="<?php echo $vo['id'] ?>" data-name="<?php echo $vo['name'] ?>" data-abri="<?php echo $vo['abridge'] ?>"><?php echo $vo['name'] ?></a>
                        <?php endforeach ?>
                        </span>
                    </h2>
                    <!-- 检索 -->
                    <div class="g_search">
                        <!-- <input type="text">
                        <a href="javascript:;">快速搜索</a> -->
                    </div>
                    <!-- END -->
                    <div class="cancel">X</div>
                </div>
                <div class="g_hot">
                    <div class="g_hot_t">
                        <a href="javascript:;" class="hot on">热门游戏</a>
                        <?php foreach ($letters as $k => $v): 
                            if(isset($games[$v]) && $games[$v]){ 
                        ?>
                            <a href="javascript:;"><?php echo $v; ?></a>
                        <?php 
                            } 
                            endforeach 
                        ?>
                    </div>
                    <!-- 热门游戏 -->
                    <div class="g_name_list active">
                        <?php foreach ($games['hot'] as $key => $vo): ?>
                            <a href="javascript:;">
                                <div class="g_one" onclick="chooseGame(this)" data-id="<?php echo $vo['id'] ?>" data-name="<?php echo $vo['name'] ?>" data-abri="<?php echo $vo['abridge'] ?>">
                                    <img src="<?php echo IMG_PATH ?>index/games/<?php echo $vo['abridge'] ?>.png"/>
                                    <p><?php echo $vo['name'] ?></p>
                                </div>
                            </a>
                        <?php endforeach ?>
                    </div>
                    <?php unset($games['hot']); ?>
                    <?php foreach ($games as $k => $val): 
                            if(!empty($val)){ 
                    ?>
                        <div class="g_name_list">
                            <?php foreach ($val as $_game): ?>
                                <a href="javascript:;">
                                    <div class="g_one" onclick="chooseGame(this)" data-id="<?php echo $_game['id'] ?>" data-name="<?php echo $_game['name'] ?>" data-abri="<?php echo $_game['abridge'] ?>">
                                        <img src="<?php echo IMG_PATH ?>index/games/<?php echo $_game['abridge'] ?>.png"/>
                                        <p><?php echo $_game['name'] ?></p>
                                    </div>
                                </a>
                            <?php endforeach ?>
                        </div>
                    <?php 
                        }
                        endforeach 
                    ?>
                </div>
            </div>

            <div class="game_n">
                <div class="g_tit">
                    <h2>
                        <span>请选择游戏区：</span>
                    </h2>
                    <div class="cancel">X</div>
                </div>
                <div class="g_hot_wr area1"></div>
            </div>
            <div class="game_n">
                <div class="g_tit">
                    <h2>
                        <span>请选择游戏服务器：</span>
                    </h2>
                    <div class="cancel">X</div>
                </div>
                <div class="g_hot_wr area2"></div>
            </div>
            <div class="game_n ">
                <div class="g_tit">
                    <h2>
                        <span>请选择游戏物品类型：</span>
                        <!-- <a>全部区</a> -->
                    </h2>
                    <div class="cancel">X</div>
                </div>
                <div class="g_hot_wr area3"></div>
            </div>
            <div class="game_n">
                <div class="g_tit">
                    <h2>
                        <span>请选择交易身份：</span>
                    </h2>
                    <div class="cancel">X</div>
                </div>
                <div class="g_hot_wr area4">
                    <div class="p_one" data-name="买家" data-abri="buyer"  onclick="chooseIdent(this)">
                        <b></b>
                        <a href="javascript:;">买家</a>
                    </div>
                    <div class="p_one" data-name="卖家" data-abri="seller" onclick="chooseIdent(this)">
                        <b></b>
                        <a href="javascript:;">卖家</a>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 提交表单 -->
        <form id="postForm" action="<?php echo U('index/search') ?>" method="get">
            <!-- 游戏编码 -->
            <input type="hidden" name="gm"> 
            <!-- 区服编码 -->
            <input type="hidden" name="ar">
            <!-- 物品类型 -->
            <input type="hidden" name="ty">
            <!-- 身份 -->
            <input type="hidden" name="cr">
        </form>
    </div>
    <?php include getTpl('login', 'public'); ?>
    <?php include getTpl('footer', 'public');  ?>
</div>
</body>
<script>
    $(function(){
        $(".p_type a").click(function(){
            var num=$(this).index();
            $(".game_n").eq(num).addClass("active").siblings(".game_n").removeClass("active");
            $(".gameBox").get(0).className = 'gameBox';
            $(".gameBox").addClass("wr"+(num*1+1));
        });

        $(".g_hot_t a").click(function(){
            $(this).addClass("on").siblings("a").removeClass("on");
            var num=$(this).index();
            $(".g_name_list").eq(num).addClass("active").siblings(".g_name_list").removeClass("active");
        })

        //提交表单
        $("#subBtn").click(function(){
            var g = $("input[name=gm]").val();
            var a = $("input[name=ar]").val();
            var t = $("input[name=ty]").val();
            var c = $("input[name=cr]").val();
            if(!g || !a || !t || !c) {
                return false;
            }
            $("#postForm").submit();
        });

        $(".cancel").click(function(){
            $(this).parents(".game_n ").removeClass("active");
            $(".gameBox").get(0).className = 'gameBox';
        })

        $(".price_title h2 a").click(function(){
            $(this).addClass("on").siblings("a").removeClass("on");
            var url = $(this).attr('data-url');
            $("#postForm").attr('action' , url);
        })
    });
    // 选择游戏
    function chooseGame(obj) {
        $("#gameName").text($(obj).attr('data-name'));
        $("#gameArea").text("游戏大区");
        $("#gameServer").text("游戏服务器");
        $("#gameType").text("物品类型");
        $(".area2").html("");
        //清空表单
        resetForm();
        //加入表单
        $("input[name=gm]").val($(obj).attr('data-abri'));
        var game_id = $(obj).attr('data-id');
        $.getJSON("<?php echo U('index/getAreaByGameId') ?>", {game_id : game_id} , function(result){
            if(result.status == 1){
                $(".area1").html(result.data);
            }
        });
        //获取物品类型
        $.getJSON("<?php echo U('index/getStdmodeByGameId') ?>", {game_id : game_id}, function(result){
            if(result.status == 1) {
                $(".area3").html(result.data);
            }
        });
        //设置搜索历史
        $.getJSON("<?php echo U('index/setHistory') ?>" , {game_id : game_id} , function(result){
            if(result.status == 1) {
                $(".history").html(result.data);
            }
        });

        $(obj).parents(".game_n ").removeClass("active").next(".game_n").addClass("active");
        $(".gameBox").get(0).className = 'gameBox';
        $(".gameBox").addClass("wr2");
    }

    //获取服信息
    function getServer(obj) {
        $(obj).addClass('on').siblings(".p_one").removeClass('on');
        $("#gameArea").text($(obj).attr('data-name'));
        $("#gameServer").text("游戏服务器");
        //清除
        $("input[name=ar]").val(''); 
        var area_id = $(obj).attr('data-id');
        $.getJSON("<?php echo U('index/getServerByAreaId') ?>" , {area_id , area_id}, function(result){
            if(result.status == 1){
                $(".area2").html(result.data);
            }
        });
        $(obj).parents(".game_n ").removeClass("active").next(".game_n").addClass("active");
        $(".gameBox").get(0).className = 'gameBox';
        $(".gameBox").addClass("wr3");
    }

    //物品类型
    function getGameType(obj) {
        $(obj).addClass('on').siblings(".p_one").removeClass('on');
        $("#gameServer").text($(obj).attr('data-name'));
        //加入表单
        $("input[name=ar]").val($(obj).attr('data-abri'));
        $(obj).parents(".game_n ").removeClass("active").next(".game_n").addClass("active");
        $(".gameBox").get(0).className = 'gameBox';
        $(".gameBox").addClass("wr4");
    }

    //选择身份
    function getIdent(obj) {
        $(obj).addClass('on').siblings(".p_one").removeClass('on');
        $("#gameType").text($(obj).attr('data-name'));
        //加入表单
        $("input[name=ty]").val($(obj).attr('data-abri'));
        $(obj).parents(".game_n ").removeClass("active").next(".game_n").addClass("active");
        $(".gameBox").get(0).className = 'gameBox';
        $(".gameBox").addClass("wr5");
    }

    //提交检索信息
    function chooseIdent(obj) {
        $(obj).addClass('on').siblings(".p_one").removeClass('on');
        $("#ident").text($(obj).attr('data-name'));
        //加入表单
        $("input[name=cr]").val($(obj).attr('data-abri'));
        $(obj).parents(".game_n").removeClass("active");
        $(".gameBox").removeClass("wr5");
        var g = $("input[name=gm]").val();
        var a = $("input[name=ar]").val();
        var t = $("input[name=ty]").val();
        var c = $("input[name=cr]").val();
        if(!g || !a || !t || !c) {
            return false;
        }
        //历史详情需要登录
        if($(".hq").hasClass('on')) {
            var isLogin = "<?php echo isHave(user::$userInfo['uid']) ? 1 : 2; ?>";
            if(isLogin == 2) {
                var refer_url = "<?php echo U('index/records') ?>?"+'gm='+g+"&ar="+a+"&ty="+t+"&cr="+c;
                $("#login").click();
                $('#refer').val(encodeURIComponent(refer_url));
                return false;
            }
        }
        $("#postForm").submit();
    }

    //清空表单
    function resetForm() {
         $(":input","#postForm")
        .not(":button",":reset","hidden","submit")
        .val("")
        .removeAttr("checked")
        .removeAttr("selected");
    }
</script>
</html>